<template>
    <div>
        <h4>添加页面</h4>
<table>
    <tr>
        <td>姓名</td>
        <td><input type="text" v-model="data.name"></td>
    </tr>
    <tr>
        <td>年龄</td>
        <td><input type="text" v-model="data.age" ></td>
    </tr>
    <tr>
        <td>性别</td>
        <td><input type="radio":value="1" name=1 v-model="data.sex">男
            <input type="radio":value="2" name=1 v-model="data.sex" >女</td>
    </tr>
    <tr>
        <td>生日</td>
        <td><input type="date" v-model="data.birthday" ></td>
    </tr>
    <tr>
        <td>等级</td>
        <td><select  v-model="data.mid" >
            <option value="0">请选择</option>
            <option v-for="d in sele":value="d.mid"  >{{d.mname}}</option>
        </select></td>
    </tr>
    <tr>
        <td>图片</td>
        <td><input type="file" @change="upload" >
            <img :src="'https://localhost:7183/'+data.img" alt="" width="140px" height="140px" >
        </td>
    </tr>
    <tr>
        <td>状态</td>
        <td><input type="checkbox" name="a" v-model="data.state" >勾选时为启用</td>
    </tr>
    <tr>
        <td><input type="button" @click="Add" value="添加" ></td>
    </tr>
    
    
</table>
    </div>
</template>

<script setup lang="ts">
import {ref,onMounted} from "vue"
import axios from "axios"
import { useRoute } from "vue-router";
import moment from "moment";
import router from "@/router";
const rote=useRoute();
const  data=ref({
"name": "",
"age": 0,
"sex": 0,
"birthday": "",
"createtime": "2025-04-04T08:49:36.069Z",
"mid": 0,
"img": "",
"state": true,
"isdele": true
})
const ft=()=>{
    var zid=rote.query.id
    axios.get("https://localhost:7183/api/User/Get",{params:{id:zid}}).then(res=>{
        
        data.value=res.data
        data.value.birthday=moment(res.data.birthday).format("YYYY-MM-DD")
    })
}
const  sele=ref([{
     "mid": 1,
    "mname": "VIP"
}])
onMounted(()=>{
    selep();
    ft();
})
const  upload=(e:any)=>{
var path=e.target.files[0]
var tu=new FormData()
tu.append("file",path)
axios.post("https://localhost:7183/api/User/upload",tu).then(res=>{
data.value.img=res.data
})
}
const selep=()=>{
    axios.get("https://localhost:7183/api/User/sele").then(res=>{
        sele.value=res.data
    })
}
const Add=()=>{
    debugger
    axios.put("https://localhost:7183/api/User/Update",data.value).then(res=>{
        if(res.data>0)
    {
        alert('修改成功')
        router.push({path:"/list"})
    }
    else
    {
        alert('修改失败')
    }
    })
}
</script>

<style scoped>

</style>